import curses

class SearchWin:

    def __init__(self, screen):
        _, max_x = screen.getmaxyx()

        self.win = curses.newwin(3, max_x, 0, 0)
        self.screen = screen
        self.is_current = False
        
        self.query = ""
        self.title = "Search"
        self.standart_text = "Search..."

    def _is_valid_operand(self, other):
        return (hasattr(other, "title") and
                hasattr(other, "query"))

    def __eq__(self, other):
        if not self._is_valid_operand(other): return False
        return self.title == other.title

    def clear(self):
        self.win.erase()

    def draw(self):
        max_y, max_x = self.screen.getmaxyx()

        if self.is_current: self.win.attron(curses.A_BOLD)

        self.win.box()
        self.win.addstr(0, 2, self.title)
        self.win.addstr(1, 1, self.standart_text)

        self.win.attroff(curses.A_BOLD)

    def refresh(self):
        self.win.refresh()

    def getch(self):
        return self.win.getch()

    def set_current(self):
        self.is_current = True

    def set_uncurrent(self):
        self.is_current = False

